package com.googlecode.imule.media;

import java.io.IOException;

import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;

/**
 * A simple component to handle the playing of media.
 *  
 * @author Neil Cowzer
 */
public class IPlayer {
	
	String ip;
	
	// the player
	private Player player = null;
	
	public IPlayer(String ip) {
		this.ip = ip;
	}
	
	public void start(){
		String mediaFile = "rtp://"+ip+":9000/audio";
		System.out.println(mediaFile);
		MediaLocator mlr = new MediaLocator( mediaFile );
		
		try {
			player = Manager.createRealizedPlayer( mlr );
		} catch (NoPlayerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (CannotRealizeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		player.start();		
	}
	
	public void stop(){
        player.stop();

        player.deallocate();

        player.close();
	}
	


}
